<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 14-10-30
 * Time: 上午9:37
 */
header('Content-type:text/html;charset:utf-8');
function upload_multi($path,$photo,$i){

    $uploaddir = './'.$path;
    if(!file_exists($uploaddir)){
        $uploaddir = mkdir($uploaddir);
        return true;
    }
    $piece = explode('.',$photo['name'][$i]);
    $uploadfile = $uploaddir.'./'.md5($piece['0']).'.'.$piece['1'];
    $result = move_uploaded_file($photo['tmp_name'][$i],$uploadfile);

    if(!$result){
        exit('上传失败');
    }
}

if($_POST['sel']){
    $i=0;
    foreach($_FILES['pic']['error'] as $key=>$error){
        if($error == UPLOAD_ERR_OK){
            upload_multi('upload',$_FILES['pic'],$i);
        }
        $i++;
    }
    echo "<script>alert('上传成功');location='upload.html'</script>";
}